package LeetCode;

public class Code279_numSquares {

    public int numSquares(int n) {
        int[] dp = new int[n+1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j * j <= i; j++){
                dp[i] = dp[i] == 0 ? (dp[i-j*j] + 1) : Math.min(dp[i], dp[i-j*j] + 1);
            }
        }
        return dp[n];
    }

    public static void main(String[] args) {
        Code279_numSquares code279_numSquares = new Code279_numSquares();
        System.out.println(code279_numSquares.numSquares(13));
    }

}
